using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

using Castle.Core.Interceptor;
using Castle.Facilities.PolicyInjection;

namespace TestConsole.Policies.Rules
{
    [RuleConfiguration()]
    public class VoidMethodRule : IRule
    {
        public bool IsMatch(Type componentType, IDictionary<string, string> configurationAttributeCollection)
        {
            MethodInfo[] methods = componentType.GetMethods();
            foreach (MethodInfo methodInfo in methods)
            {
                if (methodInfo.ReturnType == typeof(void))
                {
                    return true;
                }
            }
            return false;
        }

        public bool IsIntercept(IInvocation invocation, IDictionary<string, string> configurationAttributeCollection)
        {
            if (invocation.Method.ReturnType == typeof(void))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
